using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using MicroFractal.iTunesBrowser.Core.Data.ITunesDB;

namespace MicroFractal.iTunesBrowser.Core.Data.ITunesDB.Item
{
    public class StringData : Header.Header
    {

        #region Constructors

        public StringData(MemoryStream data)
            : base(data)
        {
            _totalLength = Helper.ITunesHelper.BytesToInt(data, 8, 4);
            _type = (StringDataTypeEnum)Helper.ITunesHelper.BytesToInt(data, 12, 4);
            _value = Helper.ITunesHelper.BytesToString(data, 40, _totalLength - base.Length, Encoding.Unicode).Replace("\0", "");//Encoding.Unicode.GetString(reader.ReadBytes(_totalLength - base.Length)).Replace("\0", "");
        }

        #endregion

        #region Properties

        private StringDataTypeEnum _type;
        /// <summary>
        /// Obtiene o establece el tipo de String.
        /// </summary>
        public StringDataTypeEnum StringType
        {
            get { return _type; }
            set { _type = value; }
        }

        private string _value;
        /// <summary>
        /// Obtiene o establece el valor
        /// </summary>
        public string Value
        {
            get { return _value; }
            set { _value = value; }
        }

        private int _totalLength;

        public int TotalLength
        {
            get { return _totalLength; }
            set { _totalLength = value; }
        }

        #endregion
    }

    public enum StringDataTypeEnum
    {
        Title = 1,
        Location = 2, //(this string should be less than 112 bytes/56 UTF-16 chars (not including the terminating \0) or the iPod will skip the song when trying to play it)  
        TrackAlbum = 3,
        TrackArtist = 4,
        Genre = 5,
        Filetype = 6,
        EQSetting = 7,
        Comment = 8,
        Category = 9, //- This is the category ("Technology", "Music", etc.) where the podcast was located. Introduced in db version 0x0d.  
        Composer = 12,
        Grouping = 13,
        Description = 14, //text (such as podcast show notes). Accessible by selecting the center button on the iPod, where this string is displayed along with the song title, date, and timestamp. Introduced in db version 0x0d.  
        PodcastEnclosureURL = 15,//Note: this is either a UTF-8 or ASCII encoded string (NOT UTF-16). Also, there is no mhod::length value for this type. Introduced in db version 0x0d.  
        PodcastRSSURL = 16,// Note: this is either a UTF-8 or ASCII encoded string (NOT UTF-16). Also, there is no mhod::length value for this type. Introduced in db version 0x0d.  
        Chapterdata = 17, // This is a m4a-style entry that is used to display subsongs within a mhit. Introduced in db version 0x0d.  
        Subtitle = 18, //(usually the same as Description). Introduced in db version 0x0d.  
        Show = 19, //(for TV Shows only). Introduced in db version 0x0d?  
        EpisodeNumber = 20, //  (for TV Shows only). Introduced in db version 0x0d?  
        TVNetwork = 21, //(for TV Shows only). Introduced in db version 0x0d?  
        AlbumArtist = 22, // Introduced in db version 0x13? 
        ArtistName = 23, // for sorting. Artists with names like "The Beatles" will be in here as "Beatles, The". Introduced in db version 0x13? 
        AppearsToBeAListOfKeywordsPertainingToATrack = 24,// Introduced in db version 0x13? 
        LocaleforTVShow = 25,//? (e.g. "us-tv||0|", v.0x18) 

        SortingTitle = 27, //for sorting. 
        SortingAlbum = 28,// for sorting. 
        SortingAlbumArtist = 29,// for sorting. 
        SortingComposer = 30,// for sorting. 
        TVShow = 31, //for sorting. 
        Unknown = 32, //created by iTunes 7.1 for video tracks. Binary field, no string. 
        SmartPlaylistData = 50,
        SmartPlaylistRules = 51,
        LibraryPlaylistIndex = 52,
        Unknown2 = 53, // created by iTunes 7.2, similar to MHOD52  
        Seemstovary = 100, //iTunes uses it for column sizing info as well as an order indicator in playlists.  
        Album = 200,//(in Album List, iTunes 7.1)  
        Artist = 201, //(in Album List, iTunes 7.1)  
        OldSortingArtist = 202,// for sorting (in Album List, iTunes 7.1)  
        PodcastUrl = 203, //(in Album List, iTunes 7.1)  
        OldTVShow = 204 //(in Album List, v. 0x18)  
    }
}
